#include "HelloWorldScene.h"

using namespace cocos2d;

CCScene* HelloWorld::scene()
{
    CCScene *scene = CCScene::create();
    
    HelloWorld *layer = HelloWorld::create();
    
    scene->addChild(layer);
    
    return scene;
}

bool HelloWorld::init()
{
    if ( !CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)) )
    {
        return false;
    }
    
    /////////////////////////////
    
    
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    
    // 메뉴 아이템 생성 및 초기화
    
    CCMenuItemFont* pMenuItem1 = CCMenuItemFont::create("fucking",
                                                        this,
                                                        menu_selector(HelloWorld::doAction) );
    pMenuItem1->setColor(ccc3(100, 0, 0));
    
    // 메뉴 생성
    CCMenu* pMenu = CCMenu::create(pMenuItem1, NULL);
    
    // 메뉴 위치 지정
    pMenu->setPosition( ccp(s.width / 5, 50) );
    
    // 레이어에 메뉴 객체 추가
    this->addChild(pMenu);
    
    
    // 동그란 버튼 스프라이트 추가
    pBall = CCSprite::create("Images/r1.png");
    pBall->setPosition(ccp(50, 150));
    pBall->setScale(0.7);
    this->addChild(pBall);
    
    
    // Grossini 씨의 스프라이트 추가
    pMan = CCSprite::create("Images/grossini.png");
    pMan->setPosition(ccp(50, 150));
    pMan->setScale(0.5);
    this->addChild(pMan);
    
    // Grossini 씨의 sister1 스프라이트 추가
    pWomen1 = CCSprite::create("Images/grossinis_sister1.png");
    pWomen1->setPosition(ccp(50, 150));
    pWomen1->setScale(0.5);
    this->addChild(pWomen1);
    
    // Grossini 씨의 sister2 스프라이트 추가
    pWomen2 = CCSprite::create("Images/grossinis_sister2.png");
    pWomen2->setPosition(ccp(50, 150));
    pWomen2->setScale(0.5);
    this->addChild(pWomen2);
    
    
    
    return true;
}

#define CCCA(x)   (x->copy()->autorelease())
void HelloWorld::doAction(CCObject* pSender)
{
    // EaseExponential, EaseSine, EaseBack
    
    doActionReset();
    
    // 정상 속도
    CCActionInterval* move = CCMoveBy::create(3.0f, ccp(400,0));
	
	CCActionInterval* move1 = CCMoveTo::create(0.3f, ccp(400,300));
	CCActionInterval* move2 = CCMoveTo::create(0.3f, ccp(0,300));

	CCFiniteTimeAction* seq=CCSequence::create(move1,move2, NULL);
    
    
    // 속도 -----------------------------------------
    // 빨라지기 : 시작이 늦고 나중에 빠름
//    CCActionInterval* move_ease_in = CCEaseIn::create((CCActionInterval*)(move->copy()->autorelease()), 4.0f);
    // 느려지기 : 시작이 빠르고 나중에 늦음
//    CCActionInterval* move_ease_out = CCEaseOut::create((CCActionInterval*)(move->copy()->autorelease()), 4.0f);
    // 빨라졌다 느려지기 : 시작과 끝이 빠르고 중간이 늦음
//    CCActionInterval*  move_ease_inout1 = CCEaseInOut::create((CCActionInterval*)(move->copy()->autorelease()), 2.0f);
//    CCActionInterval*  move_ease_inout2 = CCEaseInOut::create((CCActionInterval*)(move->copy()->autorelease()), 1.35f);
//    CCActionInterval*  move_ease_inout3 = CCEaseInOut::create((CCActionInterval*)(move->copy()->autorelease()), 1.0f);
    
    // 탄성 -----------------------------------------
/*    CCActionInterval* move_ease_in = CCEaseElasticIn::create((CCActionInterval*)(move->copy()->autorelease()), 0.4f);
    CCActionInterval* move_ease_out = CCEaseElasticOut::create((CCActionInterval*)(move->copy()->autorelease()), 0.4f);
    CCActionInterval* move_ease_inout1 = CCEaseElasticInOut::create((CCActionInterval*)(move->copy()->autorelease()), 0.4f);
    CCActionInterval* move_ease_inout2 = CCEaseElasticInOut::create((CCActionInterval*)(move->copy()->autorelease()), 0.45f);
    CCActionInterval* move_ease_inout3 = CCEaseElasticInOut::create((CCActionInterval*)(move->copy()->autorelease()), 0.6f);
  */  
    // 바운스 ---------------------------------------
  /*  CCActionInterval* move_ease_in = CCEaseBounceIn::create((CCActionInterval*)(move->copy()->autorelease()) );
    CCActionInterval* move_ease_out = CCEaseBounceOut::create((CCActionInterval*)(move->copy()->autorelease()) );
    CCActionInterval* move_ease_inout1 = CCEaseBounceInOut::create((CCActionInterval*)(move->copy()->autorelease()) );
    */
    
    // 스피드 ---------------------------------------
    CCSpeed* move_ease_in = CCSpeed::create((CCActionInterval*)(move->copy()->autorelease()), 1.0);
    CCSpeed* move_ease_out = CCSpeed::create((CCActionInterval*)(move->copy()->autorelease()), 2.0);
    CCSpeed* move_ease_inout1 = CCSpeed::create((CCActionInterval*)(move->copy()->autorelease()), 3.0);
    
    
    
    
    pBall->runAction(move_ease_in);
    pMan->runAction(move_ease_out);
    pWomen1->runAction(move_ease_inout1);
    pWomen2->runAction(seq);
    
}

void HelloWorld::doActionReset()
{
    pBall->setPosition(ccp(50, 100));
    pBall->setScale(0.7);
    
    pMan->setPosition(ccp(50, 150));
    pMan->setScale(0.5);
    
    pWomen1->setPosition(ccp(50, 220));
    pWomen1->setScale(0.5);
    
    pWomen2->setPosition(ccp(50, 280));
    pWomen2->setScale(0.5);
}


